package com.ff.xyh.consumer.messagedeliver.controller;

import com.ff.xyh.common.utils.JwtUtils;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.websocket.*;
import javax.websocket.server.ServerEndpoint;

/**
 * Create by Wzy
 * on 2018/8/6 13:24
 * 不短不长八字刚好
 */
//@ServerEndpoint("/online/user")
//@Component
public class OnlineUserController {

    private String userId;
    private Session session;

    /**
     * 一个用户连接时生成一个controller 一个controller也会包含一个session
     * 用户登录后保持连接 可以做在线业务
     */
    @OnOpen
    public void onOpen(Session session, HttpServletRequest request) {
        String userToken = request.getHeader("token");
        String userId = JwtUtils.getSubjectFromToken(userToken);
        this.session = session;
        this.userId = userId;


    }

    @OnClose
    public void onClose() {

    }

    /**
     * 服务端接收消息
     * @param message
     * @param session
     */
    // 客户端向服务端
    @OnMessage
    public void onMessage(final String message, Session session) {

    }

    @OnError
    public void onError(Session session, Throwable error) {

    }
}